<template>
  <div class="no-padding app-container">
    <lst-page-container>
      <template slot="query">
        <el-form :model="tableQueryParams" ref="queryForm" size="small" :inline="true" label-width="68px">
          <el-form-item label="是否本级" prop="questionTypeCode">
            <dict-check :dict-data="typeList" v-model="tableQueryParams.isSelf"></dict-check>
          </el-form-item>
          <el-form-item label="整改状态" prop="repairState">
            <dict-check @change="getList" :dict-data="dict.type.enum_question_repair"
                        v-model="tableQueryParams.repairState"></dict-check>
          </el-form-item>
          <el-form-item label="所属机构" prop="orgParam">
            <el-cascader v-model="tableQueryParams.orgParam" :props="orgParamProps"></el-cascader>
          </el-form-item>
          <el-form-item label="隐患类型" prop="questionTypeParam">
            <el-cascader v-model="tableQueryParams.questionTypeParam" :props="questionTypeParamProps"></el-cascader>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
      </template>

      <template slot="table">
        <el-table  @sort-change="handleSortChange"  height="100%" v-loading="loading" :data="dataList">
          <el-table-column :sortable="colum.sortable" v-for="(colum,index) in questionTableColum" :key="index" :width="colum.width"
                           :label="colum.label"
                           :align="colum.align" :prop="colum.propValue">
            <template slot-scope="scope">
              <question-table-colum :scope="scope" :colum-config="colum"></question-table-colum>
            </template>
          </el-table-column>
          <el-table-column width="200" label="操作" align="center" class-name="small-padding fixed-width">
            <template slot-scope="scope">
              <el-button
                  size="mini"
                  type="text"
                  icon="el-icon-edit"
                  @click="showInfo(scope.row)"
              >查看
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </template>

      <template slot="pageDisplay">
        <pagination
            v-show="total>0"
            :total="total"
            :page.sync="tableQueryParams.pageNum"
            :limit.sync="tableQueryParams.pageSize"
            @pagination="getList"
        />
      </template>
    </lst-page-container>


    <el-drawer
        class="diy-draw"
        title="隐患详情"
        :wrapperClosable="false"
        :size="HIDDEN_DANGER_WIDTH"
        :destroy-on-close="true"
        :visible.sync="infoOpen">
      <drawer-content>
        <template slot="body">
          <hidden-danger-info ref="danInfo" :info-data="infoData" :inspect-info="inspectInfo"></hidden-danger-info>
        </template>
        <template slot="footer" v-if="infoData.allowCheck  == 1">
          <el-button type="primary" icon="el-icon-search" size="mini"
                     @click="audit(AUDIT_TYPE.pass,[infoData.id])">通过
          </el-button>
          <el-button icon="el-icon-refresh" size="mini"
                     @click="audit(AUDIT_TYPE.sendBack,[infoData.id])">
            退回
          </el-button>
        </template>
      </drawer-content>
    </el-drawer>
  </div>
</template>

<script>
import {listPageMixins} from "@/mixins/listPageMixins";
import ShowFileList from "@/components/ShowFileList/index.vue";
import {subPageMixin} from "@/views/checkBusPage/mixins/subPageMixins";
import ChooseQuestion from "@/views/components/ChooseQuestion/index.vue";
import infoTable from "@/views/components/InfoTable/index.vue";
import {
  supLeaderCheckNoQuestion,
  supLeaderCheckOkQuestion,
  supLeaderGetQuestionDetail,
  supLeaderQueryQuestion
} from "@/api/checkPage/supLeader";
import {HIDDEN_DANGER_WIDTH} from "@/constantData";
import HiddenDangerInfo from "@/views/checkBusPage/components/hiddenDangerInfo/index.vue";
import DrillDownQuery from "@/components/DrillDownQuery/index.vue";
import DictCheck from "@/components/DictCheck/index.vue";
import {
  defectQuestionQueryQueryQuestionList,
  queryOrgCondition,
  queryQuestionTypeCondition
} from "@/api/checkPage/defectQuestionQuery";
import {isArr} from "@/utils/arrayUtil";

export default {
  mixins: [listPageMixins, subPageMixin],
  components: {
    ShowFileList,
    ChooseQuestion,
    infoTable,
    HiddenDangerInfo,
    DrillDownQuery,
    DictCheck,
  },
  dicts: ['enum_question_repair'],
  data() {
    return {
      HIDDEN_DANGER_WIDTH,
      modelName: '隐患查询',
      typeList: [
        {
          label: '行政监管',
          value: '0'
        },
        {
          label: '直属监管',
          value: '1'
        },
      ],
      AUDIT_TYPE: {
        pass: 'Y',
        sendBack: 'N'
      },
      // 查询参数
      queryParams: {
        // 是否本级
        isSelf: '0',
        // 所属机构
        orgParam: null,
        // 隐患类型
        questionTypeParam: null,
        // 整改状态
        repairState: null,
      },
      otherQueryParam: {
        inspectId: this.inspectInfo.id
      },
      getListFun: defectQuestionQueryQueryQuestionList,
      getInfoFun: supLeaderGetQuestionDetail,
    }
  },
  methods: {
    getList() {
      let owner = this
      if (this.getListFun == null || typeof this.getListFun !== 'function') return;
      owner.startLoading('正在加载....')
      let {otherQueryParam, orgParamDataList, questionTypeParamDataList} = this
      let queryParam = otherQueryParam != null ? {...otherQueryParam, ...this.tableQueryParams} : this.tableQueryParams;
      let {questionTypeParam, orgParam} = queryParam
      if (isArr(questionTypeParam)) {
        queryParam.questionTypeParam = questionTypeParamDataList.find(item => item.value == questionTypeParam[questionTypeParam.length - 1])
      }
      if (isArr(orgParam)) {
        queryParam.orgParam = orgParamDataList.find(item => item.value == orgParam[orgParam.length - 1])
      }
      this.getListFun(queryParam).then(response => {
            owner.dataList = response.rows;
            owner.total = response.total;
            owner.reloadTable = false
            setTimeout(() => {
              owner.reloadTable = true
              owner.endLoading()
            }, 2)
          }
      ).catch((e) => {
        owner.endLoading()
      }).finally(() => {
      });
    },
  }
}
</script>

<style scoped>

</style>
